package com.lemon.tuvi2015;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;

import com.lemon.tuvi2015.util.TagName;
import com.lemon.tuvi2015.view.CustomActionbar;

@SuppressLint("NewApi") public class HoroscopeDetailsActivity extends Activity {
	String title, content;
	CustomActionbar actionbar;
	WebView webView;
	ProgressBar progressBar;
	TextView textView;
	TextView textViewContent;
	ScrollView scrollView;
	String Aries = "Bạch Dương";
	String Taurus = "Bạch Dương";
	String Gemini = "Song Tử";
	String Cancer = "Cự Giải";
	String Leo = "Sư Tử";
	String Virgo = "Xử Nữ";
	String Libra = "Thiên Bình";
	String Scorpio = "Hổ Cáp";
	String Sagittarius = "Nhân Mã";
	String Capricornus = "Ma Kết";
	String Aquarius = "Bảo Bình";
	String Pisces = "Song Ngư";
	String[] cunghoangdao = { Aries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius, Capricornus, Aquarius, Pisces };
	String[] cunghoangdaoContent;
	int index=0;
	
	Handler handler=new Handler();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.horoscope_details);
		cunghoangdaoContent = getResources().getStringArray(R.array.cunghoangdao);
		initView();
		Bundle extras = getIntent().getExtras();
//		if (getIntent().hasExtra(TagName.TITLE))
//			title = extras.getString(TagName.TITLE);
//		if (getIntent().hasExtra(TagName.KEY)) {
//			content = extras.getString(TagName.KEY);
//			showContent(content);
//		}
		if (getIntent().hasExtra(TagName.KEY)) {
			index = extras.getInt(TagName.KEY);
			showContent(cunghoangdaoContent[index]);
		}
		initActionbar();
	}

	void initView() {
		scrollView=(ScrollView) findViewById(R.id.scrollview);
		scrollView.setVisibility(View.VISIBLE);
		textView = (TextView) findViewById(R.id.textView);
		textViewContent= (TextView) findViewById(R.id.textViewContent);
		progressBar = (ProgressBar) findViewById(R.id.progressBar);
		webView = (WebView) findViewById(R.id.webView);
		webView.setWebViewClient(new WebViewClient() {
			public void onPageFinished(WebView view, String url) {
				webView.setVisibility(View.VISIBLE);
				progressBar.setVisibility(View.GONE);
			}
		});
		webView.setVisibility(View.GONE);
		webView.setBackgroundColor(Color.TRANSPARENT);
	    if (Build.VERSION.SDK_INT >= 11) {
	    	webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
	    }
		webView.setInitialScale(100);
		// webView.getSettings().setLoadWithOverviewMode(true);
		// webView.getSettings().setUseWideViewPort(true);
		// webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		webView.setScrollbarFadingEnabled(false);
		webView.setPadding(10, 10, 10, 10);
		webView.getSettings().setBuiltInZoomControls(true);

	}

	void initActionbar() {
		actionbar = (CustomActionbar) findViewById(R.id.header);
		OnClickListener listenerBack = new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		};
//		if (title != null && !title.equals(""))
//			actionbar.setActionbar(title, listenerBack, null);
//		else
			actionbar.setActionbar(cunghoangdao[index], listenerBack, null);
	}

	private void showContent(String content) {
//		final String mimeType = "text/html";
//		final String encoding = "utf-8";
//		Log.e("showcontent", content);
//		String data = Html.fromHtml(content).toString();
//		webView.loadDataWithBaseURL(null, data, mimeType, encoding, null);
		textViewContent.setText(content);
		 Thread t =new Thread(){
		        public void run() {
		            handler.postDelayed(new Runnable() {
		                public void run() {
		                	progressBar.setVisibility(View.GONE);
		                }
		            },2000);
		        }
		    };
		    t.start();
	}
}
